package com.ruoyi.web.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.db.domain.MerchantApplyInfo;
import com.ruoyi.db.domain.MerchantBaseInfo;
import com.ruoyi.db.model.MerchantBaseInfoParam;
import com.ruoyi.merchant.service.IMerchantApplyInfoService;
import com.ruoyi.web.service.IMerchantApplyService;
import com.ruoyi.web.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MerchantApplyService implements IMerchantApplyService {

    @Autowired
    IMerchantApplyInfoService merchantApplyInfoService;
    @Autowired
    IMerchantService merchantService;

//    @Override
//    public Integer passMerchantApply(MerchantApplyInfo merchantApplyInfo, MerchantBaseInfoParam merchantBaseInfoParam){
//
//        int i = merchantApplyInfoService.updateMerchantApplyInfo(merchantApplyInfo);
//        if (i> 0 && ObjectUtil.equals(Long.valueOf(1), merchantApplyInfo.getStatus())){
//            // 生成机构信息
//            MerchantApplyInfo merchantApplyInfo1 = merchantApplyInfoService.selectMerchantApplyInfoById(merchantApplyInfo.getId());
//
//            MerchantBaseInfo merchantBaseInfo = new MerchantBaseInfo();
//
//            merchantBaseInfo.setInfoName(merchantBaseInfoParam.getInfoName());
//            merchantBaseInfo.setDescInfo(merchantBaseInfoParam.getDescInfo());
//            merchantBaseInfo.setInfoType(merchantBaseInfoParam.getInfoType());
//            merchantBaseInfo.setMaxLoanAmount(merchantBaseInfoParam.getMaxLoanAmount());
//            merchantBaseInfo.setMaxRate(merchantBaseInfoParam.getMaxRate());
//            merchantBaseInfo.setMinRate(merchantBaseInfoParam.getMinRate());
//
//            merchantBaseInfo.setOwnerId(merchantApplyInfo1.getOwnerId());
//            merchantBaseInfo.setOwnerName(merchantApplyInfo1.getOwnerName());
//
//            merchantBaseInfo.setCompanyName(merchantApplyInfo1.getCompanyName());
//            merchantBaseInfo.setCompanyUser(merchantApplyInfo1.getCompanyPerson());
//            merchantBaseInfo.setCompanyPhone(merchantApplyInfo1.getCompanyPhone());
//            merchantBaseInfo.setCompanyLogo(merchantApplyInfo1.getCompanyLogo());
//
//            AjaxResult ajaxResult = merchantService.insertMerchantBaseInfo(merchantBaseInfo);
//            if (ajaxResult.isSuccess()){
//                return 1;
//            }else {
//                return 0;
//            }
//        }
//        return i;
//
//    }


    @Override
    public Integer passMerchantApply(MerchantApplyInfo merchantApplyInfo){

        int i = merchantApplyInfoService.updateMerchantApplyInfo(merchantApplyInfo);
        if (i> 0 && ObjectUtil.equals(Long.valueOf(1), merchantApplyInfo.getStatus())){
            // 生成机构信息
            MerchantApplyInfo merchantApplyInfo1 = merchantApplyInfoService.selectMerchantApplyInfoById(merchantApplyInfo.getId());

            MerchantBaseInfo merchantBaseInfo = new MerchantBaseInfo();

            merchantBaseInfo.setInfoName(merchantApplyInfo1.getInfoName());
            merchantBaseInfo.setInfoType(merchantApplyInfo1.getInfoType());
            merchantBaseInfo.setOwnerId(merchantApplyInfo1.getOwnerId());
            merchantBaseInfo.setOwnerName(merchantApplyInfo1.getOwnerName());
            merchantBaseInfo.setCompanyName(merchantApplyInfo1.getCompanyName());
            merchantBaseInfo.setCompanyUser(merchantApplyInfo1.getCompanyPerson());
            merchantBaseInfo.setCompanyPhone(merchantApplyInfo1.getCompanyPhone());
            merchantBaseInfo.setCompanyLogo(merchantApplyInfo1.getCompanyLogo());
            merchantBaseInfo.setPriceType("1");

            AjaxResult ajaxResult = merchantService.insertMerchantBaseInfo(merchantBaseInfo);
            if (ajaxResult.isSuccess()){
                return 1;
            }else {
                return 0;
            }
        }
        return i;
    }

}
